package com.ejd.web.vo.customer;

import java.io.Serializable;

import java.util.Date;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

import com.ejd.utils.DESPlusUtil;
import com.ejd.utils.DateTimeUtil;
import com.ejd.utils.SpringFacesUtil;
import com.ejd.web.bo.impl.Order;
import com.ejd.web.constant.EjdConstants;
import com.ejd.web.constant.ManageBeanConstants;
import com.ejd.web.vo.common.OrderPage;


@ManagedBean(name="customerOrderPage")
@SessionScoped
public class CustomerOrderPageBean implements Serializable {
	private static final long serialVersionUID = -8106629465344224758L;
	
	private String  currentYear;
	
	private OrderPage cPage;// current year order page
	
	private OrderPage pPage;// previous year order page
	

	public String getCurrentYear() {
		return currentYear;
	}

	public void setCurrentYear(String currentYear) {
		this.currentYear = currentYear;
	}

	public OrderPage getcPage() {
		return cPage;
	}

	public void setcPage(OrderPage cPage) {
		this.cPage = cPage;
	}

	public OrderPage getpPage() {
		return pPage;
	}

	public void setpPage(OrderPage pPage) {
		this.pPage = pPage;
	}

	public CustomerOrderPageBean(){
		int year = DateTimeUtil.getCurYear();
		int previousYear = year - 1;
		Date  longAgo = DateTimeUtil.getDateByString("1900-01-01");
		java.sql.Timestamp tlongAgo = DateTimeUtil.convertToTimestamp(longAgo);
		Date previousYearLastDate = DateTimeUtil.getDateByString(String.valueOf(previousYear)+"-"+"12"+"-"+"31");
		java.sql.Timestamp tpreviousYearLastDate = DateTimeUtil.convertToTimestamp(previousYearLastDate);
		Date currentYearFirstDate = DateTimeUtil.getDateByString(String.valueOf(year)+"-"+"01"+"-"+"01");
		java.sql.Timestamp tcurrentYearFirstDate = DateTimeUtil.convertToTimestamp(currentYearFirstDate);
		Date currentYearLastDate = DateTimeUtil.getDateByString(String.valueOf(year)+"-"+"12"+"-"+"31");
		java.sql.Timestamp tcurrentYearLastDate = DateTimeUtil.convertToTimestamp(currentYearLastDate);
		LoginCustomerPageBean loginCustomerPage = (LoginCustomerPageBean)SpringFacesUtil.getManagedBean(ManageBeanConstants.LOGIN_CUSTOMER_PAGE_BEAN_NAME);
		Order paraC = new Order();
		paraC.setCustomer(loginCustomerPage.getCustomerInfo());
		cPage = new OrderPage(1,10,paraC);
		cPage.setFromTime(tcurrentYearFirstDate);
		cPage.setToTime(tcurrentYearLastDate);
		cPage.getPageDatas();
		Order paraP = new Order();
		paraP.setCustomer(loginCustomerPage.getCustomerInfo());
		pPage = new OrderPage(1,10,paraP);
		pPage.setFromTime(tlongAgo);
		pPage.setToTime(tpreviousYearLastDate);
		pPage.getPageDatas();
		this.setCurrentYear(String.valueOf(year));
	}
	
	public String selectcPageNo() {
		String result = null;
		String pageNo = (String) SpringFacesUtil.getRequestParameter("pageNo");
		if (this.getcPage().getPageNo().intValue() == Integer.valueOf(pageNo).intValue()) {
			return result;
		}
		this.getcPage().setPageNo(Integer.valueOf(pageNo).intValue());
		this.getcPage().getPageDatas();
		return result;	
	}
	public String selectpPageNo() {
		String result = null;
		String pageNo = (String) SpringFacesUtil.getRequestParameter("pageNo");
		if (this.getpPage().getPageNo().intValue() == Integer.valueOf(pageNo).intValue()) {
			return result;
		}
		this.getpPage().setPageNo(Integer.valueOf(pageNo).intValue());
		this.getpPage().getPageDatas();
		return result;	
	}
	public String goOrderPay() {
		String orderId =(String) SpringFacesUtil.getRequestParameter("orderId");
		if (null == orderId || "".equals(orderId)) {
			return null;
		}
		DESPlusUtil desUtil = new DESPlusUtil();
		return EjdConstants.ORDER_PAY + "?faces-redirect=true&orderId=" + desUtil.encrypt(orderId);
	}
}
